//Copyright (c) 1998-2006 Core Solutions Limited. All rights reserved.
//============================================================================
//CURRENT VERSION iDEX.3.7.0.013
//============================================================================
//CHANGE LOG
//iDEX.3.7.0.013 : Feb 2, 2006, Ric YIK, File Created
//============================================================================

package com.erp.common.web.multirow;

import java.util.ArrayList;
import java.util.Iterator;

import org.apache.commons.collections.FilterIterator;
import org.apache.commons.collections.Predicate;

/**
 * A Java bean-compliant MultiRow List for wrapping an ArrayList of MultiRows. Used by Strut's Bean TagLib
 * 
 * @author Ric YIK
 * 
 * @see com.erp.common.web.multirow.SimpleMaintMultiRowAction
 * @see com.erp.common.web.multirow.SimpleMaintMultiRowForm
 * @see com.erp.common.web.multirow.SimpleMaintMultiRow
 */
public class SimpleMaintMultiRowList {

    private final ArrayList multiRows;

    public SimpleMaintMultiRowList(ArrayList rows) {
        super();
        this.multiRows = rows;
    }

    public SimpleMaintMultiRow getMultiRow(int pageEventSrc) {
        return (SimpleMaintMultiRow) this.multiRows.get(pageEventSrc);
    }

    public Iterator getNonDeletedRows() {
        return new FilterIterator(multiRows.iterator(), new Predicate() {
            public boolean evaluate(Object nextObject) {
                return !((SimpleMaintMultiRow) nextObject).isDeleted();
            }
        });
    }

    public boolean isHavingNonDeletedRows() {
        return !this.multiRows.isEmpty();
    }

    public Iterator getAssociatableRows() {
        return new FilterIterator(multiRows.iterator(), new Predicate() {
            public boolean evaluate(Object nextObject) {
                SimpleMaintMultiRow row = (SimpleMaintMultiRow) nextObject;
                return !row.isDeleted() && !row.isRowModeCreating();
            }
        });
    }

}
